package org.example;

import redis.clients.jedis.Jedis;
import redis.clients.jedis.JedisPool;

import java.util.Set;

public class RedisDemoSet {
    public static void test1(Jedis jedis) {
        System.out.println("sadd 和 smembers");
        jedis.flushAll();

        jedis.sadd("key","111","222","333");
        Set<String> key = jedis.smembers("key");
        System.out.println("key : "+ key);
    }
    public static void test2(Jedis jedis) {
        System.out.println("sismember");
        jedis.flushAll();

        jedis.sadd("key", "111", "222", "333");
        boolean key = jedis.sismember("key", "444");
        System.out.println("key : " + key);
    }
    public static void test3(Jedis jedis) {
        System.out.println("scard");
        jedis.flushAll();

        jedis.sadd("key", "111", "222", "333");
        long key = jedis.scard("key");
        System.out.println("key : " + key);

    }
    public static void test4(Jedis jedis) {
        System.out.println("spop");
        jedis.flushAll();
        jedis.sadd("key", "111", "222", "333","555","666");
        String key = jedis.spop("key");
        System.out.println("key : " + key);
    }
    private static void test5(Jedis jedis) {
        System.out.println("sinter");
        jedis.flushAll();

        jedis.sadd("key1", "111", "222", "333");
        jedis.sadd("key2", "222", "333", "444");
        Set<String> sinter = jedis.sinter("key1", "key2");
        System.out.println("sinter : " + sinter);
    }
    private static void test6(Jedis jedis) {
        System.out.println("sinterstore");
        jedis.flushAll();

        jedis.sadd("key", "111", "222", "333");
        jedis.sadd("key2", "111", "222", "444");
        long sinterstore = jedis.sinterstore("key3", "key", "key2");
        System.out.println("sinterstore : " + sinterstore);
        Set<String> key3 = jedis.smembers("key3");
        System.out.println("key3 : " + key3);
    }
    public static void main(String[] args) {
        JedisPool jedisPool=new JedisPool("tcp://127.0.0.1:8888");
        try (Jedis jedis=jedisPool.getResource()){
//            test1(jedis);
//            test2(jedis);
//            test3(jedis);
//            test4(jedis);
//            test5(jedis);
            test6(jedis);

        }
    }
}
